class MayoristaController < ApplicationController

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def index
    list
    render :action => 'list'
  end

  def list
    @mayoristas = Mayorista.paginate :page => params[:page], :per_page => DEFAULT_PER_PAGE, :order => 'nombre'
    
  end

  def new
    @mayorista = Mayorista.new

  end
  
  def create
    @mayorista = Mayorista.new(params[:mayorista])
    @mayorista.status_id = 1
    
    if @mayorista.save
      flash[:notice] = "El Mayorista se agrego correctamente."
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end

  end

  def deshabilitar
    mayorista = Mayorista.find(params[:id])
    
    mayorista.status_id = 0
    
    if mayorista.save
      flash[:notice] = "Mayorista deshabilitado ..."
      
      redirect_to :action => "index"
    end
  end
end
